#ifndef __IOMANAGER_INCLUDED
#define __IOMANAGER_INCLUDED
#include "Singleton.h"

namespace Audio
{
	namespace IO
	{
		enum FileOpenMode
		{
			FileOpenMode_In = 0x1,
			FileOpenMode_Out = 0x2,
			FileOpenMode_App = 0x4,
			FileOpenMode_Create = 0x8,
			FileOpenMode_Bin = 0x10,
		};

		struct FileOpenParameters
		{
			FileOpenMode Mode;

		};

		struct CreateFileParameters
		{
			STRING Path;
		};

		class IFile
		{
		public:
			virtual void	Open(const FileOpenParameters& p) = 0;
			virtual void	Close() = 0;
			virtual UINT32	Read(UINT8* buffer, UINT32 size) = 0;			
			virtual BOOL	Eof() = 0;
			virtual void	Seek(UINT32 pos) = 0;
			virtual UINT32	Tell() = 0;

			virtual ~IFile(){}
		};
		

		class DefaultFile : public IFile
		{
		public:
			DefaultFile(const STRING& path);
			~DefaultFile();

			void			Open(const FileOpenParameters& p);
			void			Close();
			UINT32			Read(UINT8* buffer, UINT32 size);
			void			Seek(UINT32 pos);
			UINT32			Tell();
			BOOL			Eof();

		private:
			STRING			fileName;
			IFStream*		fileHandle;
		};

		class IFileFactory
		{
		public:
			virtual IFile* CreateFile(const CreateFileParameters& p) = 0;
			virtual void DestroyFile(IFile*& f) = 0;
		};
		
		class DefaultFileFactory : public IFileFactory
		{
		public:
			virtual IFile* CreateFile(const CreateFileParameters& p);
			virtual void   DestroyFile(IFile*& f);
		};

		class IOManager : public Singleton<IOManager>
		{
		public:
			IOManager();			
			~IOManager();
			
			void   Init(IFileFactory* f);
			IFile* CreateFile(const CreateFileParameters& p);
			void   DestroyFile(IFile*& f);

		private:
			IFileFactory*  fileFactory;
		};
	}
}

#endif